<!--
 * @Description: 
 * @Author: charles
 * @Date: 2020-11-03 12:36:26
 * @LastEditors: 18222335065 2369811390@qq.com
 * @LastEditTime: 2022-09-08 14:07:06
-->
<template>
  <!-- 写html代码得地方 -->
  <!-- 只能存在一个根节点 -->
  <div>
    <!-- 
      组件封装：
      公共样式
      a页面 头部  a页面、b页面、c页面头部一样
      b页面 头部
      c页面 头部
      1.将公共样式和逻辑抽离到一个页面中  一个vue页面 就是一个组件
      2.将当前公共样式封装成组件：
        1.当前页面引入当前公共样式页面
        2.局部注册组件
          components:{Header}
        3.使用组件
          <Header></Header>
     -->
    <!-- 头部 -->
    <!-- 头部 -->
    <div class="header">
      <!-- 背景条 -->
      <div class="header_top">
        <!-- 居中模板 -->
        <div class="wrapper">
          <div style="color: black;" class="left">南开大学欢迎您！</div>
          <div style="color: black;" class="right">学校主页</div>
        </div>
      </div>
      <!-- <div style="height:10px; background-color: #63b8d5;"></div> -->
      <!-- logo -->
      <div class="header_bottom">
        <div class="wrapper">
          <!-- logo -->
          <div class="logo">
            <!-- @表示src -->
            <img @click="$router.push('/home')" height="70px" src="@/assets/yxtx/logo.png" alt="" />
          </div>
          <!-- 栏目分类 -->
          <div class="article">
            <ul>
              <!-- 绑定事件 v-on:事件类型 简写为@事件类型 -->
              <!-- [{category:{name}},{},{}] -->
              <li @click='toArticle(item.category)' :class='$route.query.name===item.category.name?"current":""' v-for="item in categories" :key="item.id">
                {{ item.category.name }}
              </li>
            </ul>
          </div>
        </div>
        <!-- <div style="height:5px; background-color: #63b8d5;"></div> -->
      </div>
    </div>
    <!-- /头部 -->
    <!-- /头部 -->

    <!-- 体部 -->
    <div class="content">
      <!-- 轮播图 -->
      <!-- <div class="swipe">
        <el-carousel :interval="4000" type="card" height="380px">
          <el-carousel-item v-for="item in swipes" :key="item.id">
            使用v-bind绑定变量 v-bind简写为:
            <img v-bind:src="item.url" alt="" />
          </el-carousel-item>
        </el-carousel>
      </div> -->
      <div class="swipe">
        
        <el-carousel trigger="click" height="730px">
          <el-carousel-item v-for="item in swipes" :key="item.id">
            <img v-bind:src="item.url" alt="" />
            <h3 class="small">{{ item.title }}</h3>
          </el-carousel-item>
        </el-carousel>
      </div>
      <!-- 文章板块 -->
      <div class="wrapper">
        <div class="plate">
          <!-- 每一个文章板块 -->
          <!-- [{category,artilce:[]},{}] -->
          <div class="plates" v-for="cas in categories" :key="cas.category.id">
            <div class="top">
              <div class="left" @click="$router.push({
                path:'/article',
                query:cas.category
              })">{{ cas.category.name }}</div>
              <div> </div>
              <div class="right">More&nbsp;+</div>
            </div>
            
            <div class="bottom" v-if="cas.aritcle.length>0">
              <ul >
                <li @click="toDeatils(a.id)" v-for="a in cas.aritcle" :key="a.id">{{ a.title }}</li>
              </ul>
            </div>
            <div v-else>
              <a href="http://news.nankai.edu.cn/sp/system/2022/09/02/030052666.shtml" target="_blank"><img src="http://news.nankai.edu.cn/pic/003/000/475/00300047587_54fd19e9.jpg" width="370" height="228"></a>
            </div>
            
          </div>
        </div>
      </div>
    </div>
    <!-- /体部 -->

    <!-- 底部 -->
    <Footer></Footer>
    <!-- /底部 -->
  </div>
</template>
<script>
import { get, post } from "@/utils/request";
// 引入复用页面
// import Header from "@/components/Header";
// 写js代码得区域
export default {
  // components: {
  //   Header,
  // },
  data() {
    return {
      // 数据模型 存放vue变量
      // 栏目分类数组
      categories: [],
      // 轮播图数组
      swipes: [],
      id:"",
    };
  },
  // 写函数和事件处理程序
  methods: {
    // 跳转到文章详情页
    toDeatils(id){
      this.$router.push({
        path:"/list",
        query:{id}
      })
    },  
    // 获取栏目分类
    async getCategories() {
      // axios 请求 get post del
      let res = await get("/index/article/findCategoryArticles");
      console.log(res, "获取响应");
      this.categories = res.data;
      //  [{category:{name:""}},{},{},{},{}]
    },
    // 获取所有轮播图
    async getSwipes() {
      let res = await get("/index/carousel/findAll");
      //  console.log(res,'获取响应');
      this.swipes = res.data; //[{id,name,url:""},{},{}]
    },
    toArticle(item){
      // 编程式导航跳转
      this.$router.push({
        path:"/article",
        query:item
      })
    },
    // toDetails(id){
      // 编程式导航跳转
      // this.$router.push({
      //   path:'/list',
      //   query:{id}
      // })
    // },
  },
  // 生命周期 钩子函数 页面还没加载完毕发送请求
  created() {
    this.getCategories();
    this.getSwipes();
    // this.id = this.$route.query.id;
  },
};
</script>
<style lang="scss">
/* 写css代码区域 */
.header {
  background-color: rgba($color: #d4d4d4, $alpha: 0);
  user-select: none;
  .header_top {
     background-color: rgba($color: #53b7d7, $alpha: 0);

    // background-color: #ffffff;
    // background-color:white;
    .wrapper {
      display: flex;
      // 设置主轴排列方式
      justify-content: space-between;
      color: white;
      line-height: 40px;
      height: 40px;
    }
  }
  .header_bottom {
    background-color: rgba($color: #53b7d7, $alpha: 0);

    height: 85px;
    // background-color: #53b7d7;
    // margin-top: 1px;
    // border: 1px dotted #ececec;
    color: white;
    .wrapper {
      display: flex;
      justify-content: space-between;
      .article {
        padding-top: 23px;
        ul {
          display: flex;
          justify-content: space-evenly;
          .current{
            background-color: #45afd3;
            color: white;
          }
          li {
            margin-left: 10px;
            padding: 0.8em;
            font-size: 16px;
          }
          li:hover {
            position:relative;
            background-color: rgba($color: #ebeaea, $alpha: 0.2);
            color: rgb(188, 244, 235);
            cursor: pointer;
          }
        }
      }
    }
  }
}
// 体部样式开始

.content {
  overflow: hidden;
  background-color: rgba($color: #ecf6f2, $alpha: 0.3);
  // 轮播图样式
  .swipe {
    position: fixed;
    z-index: -1;
    top: 0;
    left: 0;
    height: 730px;
    width: 100%;
    img {
      height: 730px;
      width: 100%;
    }
  }
  // 文章板块样式 vw 1520 1140 380px
  .plate {
    top:855px;
    position: absolute;
    background-color: rgba($color: #ecf6f2, $alpha: 0.75);
    // background-color: white;
    display: flex;
    flex-wrap: wrap;
    width: 1200px;
    .plates {
      width: 380px;
      height: 300px;
      margin-right: 10px;
      margin-bottom: 10px;
      border: 0.1px dotted rgb(200, 199, 199);
      .top {
        display: flex;
        justify-content: space-between;
        .left {
          text-align: center;
          font-size: 22px;
          line-height: 50px;
          width: 30%;
          color: black;
          border:3px dotted #ecf6f2;
          background-color:  rgba($color: #fcece6, $alpha: 0.5);
          cursor: pointer;
          // border-bottom: 4px solid #63b8d5;
        }
        .right {
          font-size: 16px;
          line-height: 50px;
          color: black;
          cursor: pointer;
        }
        .left:hover{
          color: #63b8d5;
        }
        .right:hover{
          color: #63b8d5;
        }
      }
      .bottom {
        margin-top: 10px;
        line-height: 45px;
        ul {
          li {
            padding-left: 8px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            border-bottom: 2px dashed #ececec;
            cursor: pointer;
          }
          li:nth-child(5n){
            border-bottom: none;
          }
          li:hover{
            color: #63b8d5;
          }
        }
      }
    }
    
    .plates:nth-child(3n) {
      margin-right: 0;
    }
  }
}
.footer {
    position: absolute;
    top: 1500px;
    width: 100%;
    text-align: center;
    background-color: #63b8d5;
    color: white;
  }
// 体部样式结束
</style>